#include "es_Buffer.h"



template <class T>
void es_Buffer<T>::put(T data)
{
	_buf[_wloc++] = data;
	_wloc %= (ES_BUFFER_SIZE - 1);		//求余操作，作用是循环写入缓存。
	_dataSize++;

	return;
}

template <class T>
T es_Buffer<T>::get(void)
{
	T data_pos = _buf[_rloc++];
	_rloc %= (ES_BUFFER_SIZE - 1);		//求余操作，循环读取缓存
	_dataSize--;

	return data_pos;
}

template <class T>
T *es_Buffer<T>::head(void)
{
	T *data_pos = &_buf[0];

	return data_pos;
}

//缓存活动性
template <class T>
uint32_t es_Buffer<T>::available(void)
{
	return (_wloc == _rloc) ? 0 : 1;		//读指针不等于写指针时，说明缓存中有内容
}


template <class T>
es_Buffer<T>::es_Buffer()
{	
	clear();
}

template<typename T>
uint32_t es_Buffer<T>::getSize()
{
	return _dataSize;
}

template <class T>
es_Buffer<T>::~es_Buffer()
{	
	return;
}


template <class T>
void es_Buffer<T>::clear(void)
{
	_wloc = 0;
	_rloc = 0;
	_dataSize = 0;
	memset(_buf, 0, ES_BUFFER_SIZE);

	return;
}

template <class T>
T es_Buffer<T>::peek()
{
	return _buf[_rloc];
}


template class es_Buffer<uint8_t>;
template class es_Buffer<int8_t>;
template class es_Buffer<uint16_t>;
template class es_Buffer<int16_t>;
template class es_Buffer<uint32_t>;
template class es_Buffer<int32_t>;
template class es_Buffer<uint64_t>;
template class es_Buffer<int64_t>;
template class es_Buffer<char>;
template class es_Buffer<wchar_t>;
